﻿using System.Collections.Generic;

namespace dk.Helper.Base.Core
{
    public class Allies : IAllies
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public Allies()
        {
            AlliesByID = new Dictionary<int, IAlly>();
            AlliesByTag = new Dictionary<string, IAlly>();
        }

        #region IAllies Members

        /// <summary>
        /// Gets the allies by ID.
        /// </summary>
        public IDictionary<int, IAlly> AlliesByID { get; private set; }

        /// <summary>
        /// Gets the allies by tag.
        /// </summary>
        public IDictionary<string, IAlly> AlliesByTag { get; private set; }

        /// <summary>
        /// Adds the specified ally.
        /// </summary>
        /// <param name="ally">The ally.</param>
        public void Add(IAlly ally)
        {
            if (!AlliesByID.ContainsKey(ally.ID))
                AlliesByID.Add(ally.ID, ally);

            if (!AlliesByTag.ContainsKey(ally.Tag))
                AlliesByTag.Add(ally.Tag, ally);
        }

        /// <summary>
        /// Determines whether this instance contains the specified ally.
        /// </summary>
        /// <param name="ally">The ally.</param>
        /// <returns>
        ///   <c>true</c> if this instance contains the specified ally; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(IAlly ally)
        {
            return AlliesByID.ContainsKey(ally.ID);
        }

        /// <summary>
        /// Removes the specified ally.
        /// </summary>
        /// <param name="ally">The ally.</param>
        public void Remove(IAlly ally)
        {
            if (AlliesByID.ContainsKey(ally.ID))
                AlliesByID.Remove(ally.ID);

            if (AlliesByTag.ContainsKey(ally.Tag))
                AlliesByTag.Remove(ally.Tag);
        }

        #endregion
    }
}